#include<stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include<unistd.h>
#include<string.h>
#define LOG "zhen"
int main()
{
    umask(0);
    int fd=open(LOG,O_CREAT|O_RDWR,0664);
    if(fd<0)
    {
        perror("open");
        return 1;
    }
    char *line="i like linux";
    ssize_t ret =write(fd,line,strlen(line));
    if(ret<0)
    {
        perror("write error");
        return -1;
    }
    lseek(fd,0,SEEK_SET);
    char buff[1024];
    ret=read(fd,buff,sizeof(buff)-1);
    if(ret<0)
    {
        perror("read error");
        return -1;
    }
    else if(ret ==0)
    {
        printf("end of file\n");
        return -1;
    }
    printf("%s\n",buff);
    close(fd);
    return 0;
}
